package com.marver.common.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.marver.common.result.Result;
import com.marver.common.result.ResultStatus;

/**
 * 404错误处理
 * @author kaede
 *
 */
@RestController
public class FinalExceptionHandler implements ErrorController {
	private Logger logger = LoggerFactory.getLogger(FinalExceptionHandler.class);
	
    @RequestMapping(value = "/error", produces = "application/json")
    public Result error(HttpServletResponse resp, HttpServletRequest req) {
    	logger.error("error");
    	resp.setHeader("Content-Disposition", "inline");
    	return new Result(ResultStatus.http_status_not_found.getErrorCodeToString(),"找不到资源,请检查请求地址！");
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}
